package LeetCode.leetcode;

/**
 * 实现strStr()
 * @author: leiwenkang02@meituan.com
 * @date: 2018/9/27
 * @time: 20:01
 */
public class Test28实现strStr {
    public static void main(String[] args) {
        System.out.println(strStr("hello", "al"));
    }
    public static int strStr(String haystack, String needle) {
        for (int i = 0; ; i++) {
            for (int j = 0; ; j++) {
                if (j == needle.length()) {
                    return i;
                }
                if (i + j == haystack.length()) {
                    return  - 1;
                }
                if (needle.charAt(j) != haystack.charAt(i + j)) {
                    break;
                }

            }
        }

    }
}
